package com.eurasia.assignment.controller.dto;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

import com.eurasia.assignment.domain.Assignment;

import lombok.Data;

@Data
public class AssignmentResponse {
    private Long id;
    private String name;
    private String course;
    private String type;
    private String createTime;
    private String finishTime;
    private String status;
    private String score;
    private Integer points;
    
    private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
    
    public static AssignmentResponse fromDomain(Assignment assignment) {
        AssignmentResponse response = new AssignmentResponse();
        response.setId(assignment.getId());
        response.setName(assignment.getName());
        response.setCourse(assignment.getCourse());
        response.setType(assignment.getType());
        
        // Format the createTime as a string
        if (assignment.getCreateTime() != null) {
            response.setCreateTime(assignment.getCreateTime().format(FORMATTER));
        }
        
        response.setFinishTime(assignment.getFinishTime());
        response.setStatus(assignment.getStatus());
        response.setScore(assignment.getScore());
        response.setPoints(assignment.getPoints());
        
        return response;
    }
} 